package com.scrum.Object;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.scrum.Connection.DBConnection;


public class Catalog {
	int id;
	String catalog;

	public Catalog() {
	}

	public Catalog(int id, String catalog) {
		super();
		this.id = id;
		this.catalog = catalog;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCatalog() {
		return catalog;
	}

	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}
	
	public static int getId(String catalog) throws ClassNotFoundException, SQLException{
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			String sql = "SELECT * FROM catalog where catalog = ?";
			con = DBConnection.connectDB();
			pstmt = con.prepareStatement(sql);
			pstmt.setString(1, catalog);
			rs = pstmt.executeQuery();
			
			while (rs.next()) {
				System.out.println("id catalog "+ rs.getInt("id"));
				return rs.getInt("id");
			}
		}
		finally {
			rs.close();
			pstmt.close();
			con.close();
		}
		return -1;
	}
	
	public static String getcatalog(int id) throws ClassNotFoundException, SQLException{
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			String sql = "SELECT * FROM catalog where id = ?";
			con = DBConnection.connectDB();
			pstmt = con.prepareStatement(sql);
			pstmt.setInt(1, id);
			rs = pstmt.executeQuery();
			
			while (rs.next()) {
				return rs.getString("catalog");
			}
		}
		finally {
			rs.close();
			pstmt.close();
			con.close();
		}
		return null;
	}
	
	public static String convert(String catalog){
		if (catalog.equals("en")) return "Entertainment Places";
		else if (catalog.equals("fo")) return "Food Places";
		else return "Rest Places";
		
	}

}
